package groupchat.client;

import com.alibaba.fastjson.JSONObject;
import groupchat.entities.ServerMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ClientHandler extends SimpleChannelInboundHandler<String> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        Channel sender = ctx.channel();
        ServerMessage serverMessage = JSONObject.parseObject(msg,ServerMessage.class);
        //说明是自己发送群聊信息
        if(serverMessage.getReceiver().equals(serverMessage.getSender())) {
            System.err.println("【我】发送了" + serverMessage.getText());
        }else {
            System.err.println("【" + serverMessage.getSender()  + "】发送了" + serverMessage.getText());
        }
    }
}
